Skip to content

Conversation

@havenS
Copy link

@havenS havenS commented Oct 13, 2025

Adds camera streaming from the main gSender client to remote browser clients, enabling users to monitor their CNC machine remotely when using Wireless CNC Control mode.

While gSender supports remote access via browser, I had no way to visually monitor my machine. This feature fills that gap by streaming the main client's camera feed to remote viewers.

Technical Implementation

Architecture:

  • WebRTC peer-to-peer streaming for low-latency video transmission (no STUN/TURN servers, LAN-only)
  • Socket.io signaling for SDP offer/answer exchange and ICE candidate negotiation
  • REST API (/api/camera/status) for camera availability polling

Client-Side (React/TypeScript):

  • CameraService (singleton): Manages MediaDevices API, camera lifecycle, and RTCPeerConnection creation
  • Camera component: Main client UI with device selection, resolution/framerate controls (720p/1080p, 15/30 FPS)
  • RemoteCameraPanel: Remote client viewer that receives WebRTC stream via Socket.io signaling
  • ConditionalRemoteCameraPanel: Auto-detects remote client mode and polls for camera availability

Server-Side (Node.js):

  • CameraSignaling service: Routes WebRTC signaling messages between main and remote clients
  • Access control: Restricts camera access to localhost + local network (192.168.x.x, 10.x.x.x, 172.16-31.x.x)
  • api.camera.js: REST endpoints for status checks with IP-based authorization

Key Technical Details:

  • Main client broadcasts MediaStream via RTCPeerConnection.addTrack()
  • Remote clients receive stream through pc.ontrack event handler
  • Settings persisted to configstore (device ID, resolution, framerate)
  • Automatic reconnection handling when main client restarts streaming

UI Integration:

  • Camera configuration in settings panel (device picker, quality presets)
  • Conditional rendering in Remote Workflow page (only shows when camera available)
  • Real-time status indicators (connecting, connected, disconnected)

Security

  • Camera access restricted to authorized LAN clients only
  • IP whitelist validation on both REST API and WebSocket connections
  • Respects existing Wireless CNC Control security model

Testing Notes

  • Tested on LAN with main client (Electron on OSX, Ubuntu and Windows) + remote browser client on phone
  • Video playback works across Chrome/Firefox/Safari
  • Handles network disconnects and camera device changes gracefully
Capture d’écran 2025-10-12 à 19 11 34 IMG_8531

havenS added 6 commits October 3, 2025 09:02
…era service initialization, settings management, and UI integration for remote clients. Add entitlements for macOS builds and update package configuration.
- Fix missing displayWebGLErrorMessage function in Visualizer component
  - Added method to handle WebGL errors with user-friendly toast notifications
  - Updated function calls to use 'this.' prefix correctly

- Fix Select component empty value error in Camera settings
  - Removed SelectItem with empty string value that caused crashes
  - Placeholder now properly handled by SelectValue component

- Fix transparent dropdown backgrounds in Camera settings
  - Added explicit background colors to all SelectContent components
  - Ensures proper contrast in both light and dark modes

These fixes resolve the white screen crash when opening camera settings
and improve the overall user experience with visible, readable dropdowns.
- Updated main client identification to use `isElectron` for better accuracy in distinguishing between local and remote clients.
- Changed URL construction in Electron to always use `localhost` for secure camera access.
- Enhanced connection logic in `RemoteCameraPanel` to ensure proper handling of peer connections and viewer disconnections.
- Added new event handling for viewer disconnects to clean up peer connections efficiently.
- Improved camera status checks and polling mechanisms in `ConditionalRemoteCameraPanel` to ensure timely updates on camera availability.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant